#include <cmath>
#include <cstdio>

bool is_prime(long long x);
bool is_palindrome(long long x, int n);
long long get_num(int n);
long long create_pali_num(long long x);

int main(int argc, char const* argv[])
{
    int n;
    scanf("%d", &n);
    if (n % 2 == 0) {
        printf("0\n");
    } else if (n <= 5) {
        long long start_num = get_num(n);
        long long end_num = get_num(n + 1);
        long long output[10000];
        int num_count = 0;
        bool flag = false;

        for (long long i = start_num; i < end_num; i++) {
            if (is_palindrome(i, n)) {
                if (is_prime(i)) {
                    output[num_count++] = i;
                }
            }
        }
        printf("%d\n", num_count);
        for (int i = 0; i < num_count; i++) {
            if (!flag) {
                printf("%lld", output[i]);
                flag = true;
            } else
                printf(" %lld", output[i]);
        }
    } else { // n = 7/n = 9
        long long start_num = get_num((n + 1) / 2);
        long long end_num = get_num((n + 1) / 2 + 1);
        long long output[10000];
        int num_count = 0;
        bool flag = false;
        for (long long i = start_num; i < end_num; i++) {
            long long pali_num = create_pali_num(i);
            if (is_prime(pali_num)) {
                output[num_count++] = pali_num;
            }
        }
        printf("%d\n", num_count);
        for (int i = 0; i < num_count; i++) {
            if (!flag) {
                printf("%lld", output[i]);
                flag = true;
            } else
                printf(" %lld", output[i]);
        }
    }

    return 0;
}

bool is_prime(long long x)
{
    if (x <= 1)
        return false;
    int bound = (int)sqrt(x) + 1;
    for (int i = 2; i < bound; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

bool is_palindrome(long long x, int n)
{
    long long num = x;
    int count = n;
    while (num != 0) {
        long long devide_num = get_num(count);
        int first_num = num / devide_num;
        int last_num = num % 10;
        if (first_num != last_num) {
            return false;
        } else {
            num %= devide_num;
            num /= 10;
            count -= 2;
        }
        //奇数情况，可以少一次判断
        if (count == 1)
            break;
    }
    return true;
}

long long get_num(int n)
{
    long long return_num = 1;
    while (n > 1) {
        return_num *= 10;
        n--;
    }
    return return_num;
}

long long create_pali_num(long long x)
{
    long long temp = x, returen_num = x;
    temp /= 10; //去掉最后一位
    while (temp > 0) {
        int last_num = temp % 10;
        returen_num = returen_num * 10 + last_num;
        temp /= 10;
    }
    return returen_num;
}
/*
纯暴力解法直接超时，可以输出答案后打表= =

特殊方法：
n为偶数时，不存在既是回文又是素数的数
而n为奇数时，直接构造回文数

为了同时保留下原始解答，当n=7或9时使用构造方法

结果迷之9分
*/